package com.common.global;

import lombok.Data;

import java.io.Serializable;

@Data
public class R<T> implements Serializable {

    private static final long serialVersionUID = 286155980914564348L;
    private String code;

    private String message;

    private T data;

    public static <T> R success(String message, T data) {
        R r = new R();
        r.setCode(String.valueOf(200));
        r.setData(data);
        r.setMessage(message);
        return r;
    }

    public static <T> R success(T data) {
        R r = new R();
        r.setCode(String.valueOf(200));
        r.setData(data);
        return r;
    }

    public static <T> R error(String code, String message, T data) {
        R r = new R();
        r.setCode(code);
        r.setData(data);
        r.setMessage(message);
        return r;
    }

    public static <T> R error(GlobalBaseEnum globalBaseEnum) {
        R r = new R();
        r.setCode(globalBaseEnum.code());
        r.setMessage(globalBaseEnum.message());
        return r;
    }

    public static <T> R error(String message) {
        R r = new R();
        r.setMessage(message);
        return r;
    }
}
